{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-04-15T07:55:03.998153600Z",
     "start_time": "2025-04-15T07:55:03.403745400Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    10\n",
      "1    11\n",
      "2    12\n",
      "3    13\n",
      "4    14\n",
      "5    15\n",
      "6    16\n",
      "7    17\n",
      "8    18\n",
      "9    19\n",
      "dtype: int64\n",
      "    0\n",
      "0  10\n",
      "1  11\n",
      "2  12\n",
      "3  13\n",
      "4  14\n",
      "5  15\n",
      "6  16\n",
      "7  17\n",
      "8  18\n",
      "9  19\n",
      "[10 11 12 13 14 15 16 17 18 19]\n"
     ]
    }
   ],
   "source": [
    "ser_obj = pd.Series(range(10, 20))#左闭右开，生成10到20的整数\n",
    "print(ser_obj) #打印输出会带有类型\n",
    "df=pd.DataFrame(ser_obj)\n",
    "print(df)#df有列索引名，不会输出数据类型    Series会输出数据类型\n",
    "# # 获取数据\n",
    "print(ser_obj.values)  #series对象的一个属性，用于获取其数据部分，不包括索引"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:20:42.257952200Z",
     "start_time": "2025-04-15T08:20:42.226672300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "RangeIndex(start=0, stop=10, step=1)\n"
     ]
    },
    {
     "data": {
      "text/plain": "dtype('int64')"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(type(ser_obj.values))#获取的数据是ndarray类型\n",
    "# # 获取索引\n",
    "print(ser_obj.index)\n",
    "ser_obj.dtype#获取series里面的数据类型"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:26:25.103951700Z",
     "start_time": "2025-04-15T08:26:25.103951700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "0    10\n1    11\n2    12\n3    13\n4    14\n5    15\n6    16\n7    17\n8    18\n9    19\ndtype: object"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ser_obj.astype(float)\n",
    "ser_obj.astype(str)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:32:03.509894900Z",
     "start_time": "2025-04-15T08:32:03.462922300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "19\n",
      "0    20\n",
      "1    22\n",
      "2    24\n",
      "3    26\n",
      "4    28\n",
      "5    30\n",
      "6    32\n",
      "7    34\n",
      "8    36\n",
      "9    38\n",
      "dtype: int64\n",
      "0    False\n",
      "1    False\n",
      "2    False\n",
      "3    False\n",
      "4    False\n",
      "5    False\n",
      "6     True\n",
      "7     True\n",
      "8     True\n",
      "9     True\n",
      "dtype: bool\n"
     ]
    }
   ],
   "source": [
    "print(ser_obj[0])\n",
    "print(ser_obj[9])\n",
    "print(ser_obj * 2)\n",
    "print(ser_obj > 15)  #对所有值进行操作"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:36:06.254163500Z",
     "start_time": "2025-04-15T08:36:06.254163500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2001    17.8\n",
      "2005    20.1\n",
      "2003    16.5\n",
      "dtype: float64\n",
      "Index([2001, 2005, 2003], dtype='int64')\n",
      "17.8\n"
     ]
    },
    {
     "data": {
      "text/plain": "array([17.8, 20.1, 16.5])"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字典变为series\n",
    "year_data = {2001: 17.8, 2005: 20.1, 2003: 16.5}\n",
    "ser_obj2 = pd.Series(year_data)#字典的键将变为series的索引\n",
    "print(ser_obj2)#打印所有数据\n",
    "print(ser_obj2.index)#拿所有索引值\n",
    "print(ser_obj2[2001])#获取索引为2001的值\n",
    "ser_obj2.values#获取所有series的值    dataframe与series在打印上的区别是多了dtype"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:45:48.000354Z",
     "start_time": "2025-04-15T08:45:47.953443100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          0         1         2         3\n",
      "0 -1.419716  1.431064 -1.186265  0.729875\n",
      "1  0.285462 -0.116342  0.520881  0.394420\n",
      "2 -2.097929  0.229914 -0.917193 -2.093611\n",
      "3  0.792215  0.222377 -0.234837 -0.420891\n",
      "4 -0.383429  0.538396 -0.868426 -1.134868\n"
     ]
    }
   ],
   "source": [
    "# 通过ndarray构建DataFrame\n",
    "t = pd.DataFrame(np.arange(12).reshape((3,4)))\n",
    "# print(t)\n",
    "array = np.random.randn(5,4)#randn生成具有正态分布的随机数\n",
    "# print(array)\n",
    "df_obj = pd.DataFrame(array)\n",
    "print(df_obj.head())   #二维数组，具有行和列索引"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:51:03.668640400Z",
     "start_time": "2025-04-15T08:51:03.668640400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       name   age      tel\n",
      "0  xiaohong  21.0  10010.0\n",
      "1  xiaogang   NaN  10000.0\n",
      "2  xiaowang  22.0      NaN\n",
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "# 字典变df\n",
    "d2 =[{\"name\" : \"xiaohong\" ,\"age\" :21,\"tel\" :10010},\n",
    "     { \"name\": \"xiaogang\" ,\"tel\": 10000} ,\n",
    "     {\"name\":\"xiaowang\" ,\"age\":22}]\n",
    "df6=pd.DataFrame(d2)#字典的key变为列索引\n",
    "print(df6)\n",
    "print(type(df6.values))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T08:59:21.290885Z",
     "start_time": "2025-04-15T08:59:21.275259Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   A          B    C  D       E        F\n",
      "0  1 2019-09-26  1.0  1  Python  wangdao\n",
      "1  1 2019-09-26  1.0  2    Java  wangdao\n",
      "2  1 2019-09-26  1.0  3     C++  wangdao\n",
      "3  1 2019-09-26  1.0  4       C  wangdao\n"
     ]
    }
   ],
   "source": [
    "dict_data = {'A': 1,\n",
    "             'B': pd.Timestamp('20190926'),\n",
    "             'C': pd.Series(1, index=list(range(4)), dtype='float32'),\n",
    "             'D': np.array([1, 2, 3, 4], dtype='int32'),\n",
    "             'E': [\"Python\", \"Java\", \"C++\", \"C\"],\n",
    "             'F': 'wangdao'}\n",
    "df_obj2 = pd.DataFrame(dict_data)\n",
    "print(df_obj2)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T09:31:27.059324200Z",
     "start_time": "2025-04-15T09:31:27.043691100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')\n",
      "RangeIndex(start=0, stop=10, step=1)\n"
     ]
    },
    {
     "data": {
      "text/plain": "A             int64\nB    datetime64[ns]\nC           float32\nD             int32\nE            object\nF            object\ndtype: object"
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(df_obj2.columns)\n",
    "print(df.index)\n",
    "df_obj2.dtypes"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T09:41:07.218467700Z",
     "start_time": "2025-04-15T09:41:07.175821900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   A          B    C  D       E        F  G\n",
      "0  1 2019-09-26  1.0  1  Python  wangdao  5\n",
      "1  1 2019-09-26  1.0  2    Java  wangdao  6\n",
      "2  1 2019-09-26  1.0  3     C++  wangdao  7\n",
      "3  1 2019-09-26  1.0  4       C  wangdao  8\n"
     ]
    }
   ],
   "source": [
    "#增加列数据，列名是自定义的\n",
    "df_obj2['G'] = df_obj2['D'] + 4\n",
    "print(df_obj2.head())#head取前5行数据"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T09:44:18.761796800Z",
     "start_time": "2025-04-15T09:44:18.761796800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'G'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "File \u001B[1;32mD:\\Program Files\\Python39\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3652\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[1;34m(self, key)\u001B[0m\n\u001B[0;32m   3651\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m-> 3652\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_engine\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_loc\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcasted_key\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m   3653\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n",
      "File \u001B[1;32mD:\\Program Files\\Python39\\lib\\site-packages\\pandas\\_libs\\index.pyx:147\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[1;34m()\u001B[0m\n",
      "File \u001B[1;32mD:\\Program Files\\Python39\\lib\\site-packages\\pandas\\_libs\\index.pyx:176\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[1;34m()\u001B[0m\n",
      "File \u001B[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7080\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[1;34m()\u001B[0m\n",
      "File \u001B[1;32mpandas\\_libs\\hashtable_class_helper.pxi:7088\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[1;34m()\u001B[0m\n",
      "\u001B[1;31mKeyError\u001B[0m: 'G'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001B[1;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[38], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;66;03m# 删除列，使用del，根据索引删除一列\u001B[39;00m\n\u001B[1;32m----> 2\u001B[0m \u001B[38;5;28;01mdel\u001B[39;00m(df_obj2[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mG\u001B[39m\u001B[38;5;124m'\u001B[39m])\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28mprint\u001B[39m(df_obj2\u001B[38;5;241m.\u001B[39mhead())\n",
      "File \u001B[1;32mD:\\Program Files\\Python39\\lib\\site-packages\\pandas\\core\\generic.py:4279\u001B[0m, in \u001B[0;36mNDFrame.__delitem__\u001B[1;34m(self, key)\u001B[0m\n\u001B[0;32m   4274\u001B[0m             deleted \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m   4275\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m deleted:\n\u001B[0;32m   4276\u001B[0m     \u001B[38;5;66;03m# If the above loop ran and didn't delete anything because\u001B[39;00m\n\u001B[0;32m   4277\u001B[0m     \u001B[38;5;66;03m# there was no match, this call should raise the appropriate\u001B[39;00m\n\u001B[0;32m   4278\u001B[0m     \u001B[38;5;66;03m# exception:\u001B[39;00m\n\u001B[1;32m-> 4279\u001B[0m     loc \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43maxes\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m-\u001B[39;49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m]\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_loc\u001B[49m\u001B[43m(\u001B[49m\u001B[43mkey\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m   4280\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_mgr \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_mgr\u001B[38;5;241m.\u001B[39midelete(loc)\n\u001B[0;32m   4282\u001B[0m \u001B[38;5;66;03m# delete from the caches\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Program Files\\Python39\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3654\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[1;34m(self, key)\u001B[0m\n\u001B[0;32m   3652\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_engine\u001B[38;5;241m.\u001B[39mget_loc(casted_key)\n\u001B[0;32m   3653\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n\u001B[1;32m-> 3654\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(key) \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01merr\u001B[39;00m\n\u001B[0;32m   3655\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m:\n\u001B[0;32m   3656\u001B[0m     \u001B[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001B[39;00m\n\u001B[0;32m   3657\u001B[0m     \u001B[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001B[39;00m\n\u001B[0;32m   3658\u001B[0m     \u001B[38;5;66;03m#  the TypeError.\u001B[39;00m\n\u001B[0;32m   3659\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_check_indexing_error(key)\n",
      "\u001B[1;31mKeyError\u001B[0m: 'G'"
     ]
    }
   ],
   "source": [
    "# 删除列，使用del，根据索引删除一列\n",
    "del(df_obj2['G'])\n",
    "print(df_obj2.head())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T09:44:49.632939600Z",
     "start_time": "2025-04-15T09:44:48.938389300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   A          B    C  D     E        F\n",
      "1  1 2019-09-26  1.0  2  Java  wangdao\n",
      "2  1 2019-09-26  1.0  3   C++  wangdao\n",
      "0    1\n",
      "1    1\n",
      "2    1\n",
      "3    1\n",
      "Name: A, dtype: int64\n",
      "   A          B    C  D    E        F\n",
      "2  1 2019-09-26  1.0  3  C++  wangdao\n",
      "3  1 2019-09-26  1.0  4    C  wangdao\n"
     ]
    }
   ],
   "source": [
    "print(df_obj2[1:3])  #取1行和2行\n",
    "print(df_obj2['A'])  #取A列\n",
    "print(df_obj2[2:])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T11:58:03.215293600Z",
     "start_time": "2025-04-15T11:58:03.184052800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    分数\n",
      "B   85\n",
      "C   77\n",
      "D  100\n"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "    '分数': [90, 85, 77, 100],\n",
    "}, index=['A', 'B', 'C', 'D'])\n",
    "\n",
    "print(df['B':'D'])  # 左闭右闭\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:09:20.738285200Z",
     "start_time": "2025-04-15T12:09:20.691348200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          a         b         c         d\n",
      "a -0.059709 -0.387403  0.494084 -0.879555\n",
      "b  1.615234  0.175062  0.173044 -1.358127\n",
      "c  1.198740  0.183703  1.380731  0.324984\n",
      "d  0.281290  1.927577  0.190061  0.654081\n",
      "e -0.737979  0.115116  0.620825  0.204359\n",
      "          b         c         d\n",
      "a -0.387403  0.494084 -0.879555\n",
      "b  0.175062  0.173044 -1.358127\n",
      "c  0.183703  1.380731  0.324984\n",
      "          b         d\n",
      "a -0.387403 -0.879555\n",
      "c  0.183703  0.324984\n"
     ]
    }
   ],
   "source": [
    "# 标签索引 loc，建议使用loc，效率更高\n",
    "# DataFrame\n",
    "df_obj = pd.DataFrame(np.random.randn(5,4),\n",
    "                      columns = list('abcd'),\n",
    "                      index=list('abcde'))\n",
    "print(df_obj)\n",
    "# 第一个参数索引行，第二个参数是列,loc或者iloc效率高于直接用取下标的方式，前闭后闭\n",
    "print(df_obj.loc['a':'c', 'b':'d']) #连续索引\n",
    "print(df_obj.loc[['a','c'], ['b','d']]) #不连续索引\n",
    "# print(df_obj.loc[['c'],['b']]) #取一个值,返回的是DataFrame类型\n",
    "# print(df_obj.loc['c','b'])  #取一个值"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:14:07.459141700Z",
     "start_time": "2025-04-15T12:14:07.459141700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          b         c         d\n",
      "c  0.183703  1.380731  0.324984\n",
      "d  1.927577  0.190061  0.654081\n"
     ]
    }
   ],
   "source": [
    "print(df_obj.iloc[2:4,1:4])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:18:57.950458400Z",
     "start_time": "2025-04-15T12:18:57.903579400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    1.615234\n",
      "b    1.927577\n",
      "c    1.380731\n",
      "d    0.654081\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(df_obj.apply(lambda x : x.max()))#取每一列的最大值"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:20:38.582669600Z",
     "start_time": "2025-04-15T12:20:38.535761800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      a     b     c     d\n",
      "a -0.06 -0.39  0.49 -0.88\n",
      "b  1.62  0.18  0.17 -1.36\n",
      "c  1.20  0.18  1.38  0.32\n",
      "d  0.28  1.93  0.19  0.65\n",
      "e -0.74  0.12  0.62  0.20\n"
     ]
    }
   ],
   "source": [
    "# 使用applymap应用到每个数据\n",
    "print(df_obj.applymap(lambda x : round(x,2)))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:22:18.190752800Z",
     "start_time": "2025-04-15T12:22:18.143706Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          a         b         c         d\n",
      "e -0.737979  0.115116  0.620825  0.204359\n",
      "d  0.281290  1.927577  0.190061  0.654081\n",
      "c  1.198740  0.183703  1.380731  0.324984\n",
      "b  1.615234  0.175062  0.173044 -1.358127\n",
      "a -0.059709 -0.387403  0.494084 -0.879555\n",
      "          d         c         b         a\n",
      "a -0.879555  0.494084 -0.387403 -0.059709\n",
      "b -1.358127  0.173044  0.175062  1.615234\n",
      "c  0.324984  1.380731  0.183703  1.198740\n",
      "d  0.654081  0.190061  1.927577  0.281290\n",
      "e  0.204359  0.620825  0.115116 -0.737979\n"
     ]
    }
   ],
   "source": [
    "#轴零是行索引排序\n",
    "df4_isort = df_obj.sort_index(axis=0, ascending=False)#默认为升序排序\n",
    "print(df4_isort)\n",
    "#轴1是列索引排序\n",
    "df4_isort = df_obj.sort_index(axis=1, ascending=False)\n",
    "print(df4_isort)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:29:05.594586500Z",
     "start_time": "2025-04-15T12:29:05.547667600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          a         b         c         d\n",
      "c  1.198740  0.183703  1.380731  0.324984\n",
      "e -0.737979  0.115116  0.620825  0.204359\n",
      "a -0.059709 -0.387403  0.494084 -0.879555\n",
      "d  0.281290  1.927577  0.190061  0.654081\n",
      "b  1.615234  0.175062  0.173044 -1.358127\n",
      "          c         d         b         a\n",
      "a  0.494084 -0.879555 -0.387403 -0.059709\n",
      "b  0.173044 -1.358127  0.175062  1.615234\n",
      "c  1.380731  0.324984  0.183703  1.198740\n",
      "d  0.190061  0.654081  1.927577  0.281290\n",
      "e  0.620825  0.204359  0.115116 -0.737979\n"
     ]
    }
   ],
   "source": [
    "#按轴零排序，by后是列名\n",
    "df4_vsort = df_obj.sort_values(by='c',axis=0, ascending=False)\n",
    "print(df4_vsort)\n",
    "#按轴1排序，by后行索引名\n",
    "df4_vsort = df_obj.sort_values(by='e',axis=1, ascending=False)\n",
    "print(df4_vsort)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:33:17.640660600Z",
     "start_time": "2025-04-15T12:33:17.609325700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       a      b      c      d\n",
      "a  False  False  False  False\n",
      "b  False  False  False  False\n",
      "c  False  False  False  False\n",
      "d  False  False  False  False\n",
      "e  False  False  False  False\n"
     ]
    }
   ],
   "source": [
    "#isnull来判断是否有空的数据\n",
    "print(df_obj.isnull())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:33:49.654982Z",
     "start_time": "2025-04-15T12:33:49.576852400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(df_obj.dropna(inplace=True))#删除缺失值"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-04-15T12:33:57.209416700Z",
     "start_time": "2025-04-15T12:33:57.193757400Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
